/*
 * @Description: 获取电影 DTO
 * @Author: fhw
 * @Date: 2024-06-15
 */

import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsOptional, IsString, IsNumber, Min, IsArray, IsDate, IsNotEmpty, IsEnum, isNumber } from 'class-validator';
import { FindOperator } from 'typeorm';
import { DiffDto, PageDto } from 'src/common/dto/dto';
import { FreeState, Status } from 'src/dictionaries/index.enum';

/** 获取电影 DTO */
export class GetMovieDto extends PageDto {
    /** 是否推荐。2：否，1：是 */
    @ApiPropertyOptional({
        type: Number,
        name: 'isRecommend',
        description: '是否推荐。2：否，1：是',
        enum: [1, 2]
    })
    public readonly isRecommend?: number;
    /** 是否上架 */
    @ApiPropertyOptional({
        name: 'status',
        description: '是否上架',
        enum: Status,
    })
    public readonly status: Status;
    /** 电影标题 */
    @ApiPropertyOptional({
        type: String,
        name: 'name',
        description: '电影标题',
    })
    public readonly name?: FindOperator<string>;

    /** 介绍 */
    @ApiPropertyOptional({
        type: String,
        name: 'introduction',
        description: '介绍',
    })
    public readonly introduction?: string;
    /** 是否免费 */
    @ApiPropertyOptional({
        type: Number,
        name: 'free',
        description: '是否免费',
    })
    public readonly free?: number;
    /** 语言 */
    @ApiPropertyOptional({
        type: String,
        name: 'lang',
        description: '电影语言',
    })
    public readonly lang?: string;

    @ApiPropertyOptional({
        type: Number,
        name: 'categoryId',
        description: '分类ID',
    })
    public readonly categoryId?: number;

}

/** 创建电影 DTO */
export class CreateMovieDto extends DiffDto {
    /** 电影标题 */
    @IsNotEmpty({ message: '电影标题不能为空' })
    @ApiProperty({
        type: String,
        name: 'name',
        description: '电影标题',
    })
    public readonly name: string;

    /** 是否推荐。2：否，1：是 */
    @IsEnum([1, 2], { message: '只能传入1, 2' }) //枚举
    @IsNotEmpty({ message: '是否推荐。2：否，1：是' })
    @ApiProperty({
        type: Number,
        name: 'isRecommend',
        description: '是否推荐。2：否，1：是',
    })
    public readonly isRecommend: number;

    /** 播放量 */
    @IsNotEmpty({ message: '播放量不能为空' })
    @IsNumber()
    @Min(0, {
        message: '播放量不能小于0'
    })
    @ApiProperty({
        type: Number,
        name: 'playCount',
        description: '播放量',
    })
    public readonly playCount: number;
    /** 是否上架 */
    @IsEnum(Status)
    @IsNotEmpty({ message: '状态不能为空' })
    @ApiProperty({
        name: 'status',
        description: '是否上架',
        enum: Status,
    })
    public readonly status: Status;
    /** 电影描述 */
    @ApiPropertyOptional({
        type: String,
        name: 'introduction',
        description: '电影描述',
    })
    public readonly introduction?: string;

    /** 剧情图片 */
    @IsNotEmpty({ message: '剧情图片不能为空' })
    @ApiProperty({
        type: String,
        name: 'cover',
        description: '剧情图片',
    })
    public readonly cover: string;
    /** 标签 */
    @ApiPropertyOptional({
        type: [String],
        name: 'tags',
        description: '电影标签',
    })
    @IsArray()
    @IsOptional()
    public readonly tags?: string[];
    /** 类型 */
    @ApiPropertyOptional({
        type: [String],
        name: 'category',
        description: '电影分类',
    })
    @IsArray()
    @IsOptional()
    public readonly category?: string[];

    /** 语言 */
    @IsNotEmpty({ message: '语言不能为空' })
    @ApiProperty({
        type: String,
        name: 'lang',
        description: '电影语言',
    })
    public readonly lang: string;

    @ApiProperty({ description: '电影是否免费' })
    @IsEnum(FreeState)
    @IsNotEmpty()
    free: FreeState;  // 新增free字段，用于表示是否免费
}


/** 更新电影 DTO */
export class UpdateMovieDto extends CreateMovieDto {
    /** 电影ID */
    @IsNotEmpty({ message: '电影ID不能为空' })
    @IsNumber()
    @ApiProperty({
        type: Number,
        name: 'id',
        description: '电影ID',
    })
    public readonly id: number;
}

export class RemoveRecommendationDto {
    /** 剧集ID */
    @IsNotEmpty({ message: '剧集ID不能为空' })
    @IsNumber()
    @ApiProperty({
        type: Number,
        name: 'movieId',
        description: '剧集ID',
    })
    public readonly movieId: number;

    /** 推荐剧集ID */
    @IsNotEmpty({ message: '推荐剧集ID不能为空' })
    @IsNumber()
    @ApiProperty({
        type: Number,
        name: 'recommendedId',
        description: '推荐剧集ID',
    })
    public readonly recommendedId: number;
}

export class AddRecommendationsDto {
    /** 剧集ID */
    @IsNotEmpty({ message: '剧集ID不能为空' })
    @IsNumber()
    @ApiProperty({
        type: Number,
        name: 'movieId',
        description: '剧集ID',
    })
    public readonly movieId: number;

    /** 推荐剧集ID */
    @IsNotEmpty({ message: '推荐剧集ID不能为空' })
    @IsArray()
    @ApiProperty({
        type: [Number],
        name: 'recommendedIds',
        description: '推荐剧集ID',
    })
    public readonly recommendedIds: number[];
}